import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/forgetPassword',
    component: () => import('@/views/login/forgetPassword'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   meta: {title: '首页', icon: 'dashboard'},
  //   children: [{
  //     path: 'dashboard',
  //     name: 'Dashboard',
  //     component: () => import('@/views/dashboard/index'),
  //     meta: {title: '首页', icon: 'dashboard'}
  //   }]
  // },
  {
    path: '/',
    component: Layout,
    redirect: '/system',
    meta: {title: '系统管理', icon: 'system'},
    children: [{
      path: 'system',
      name: 'system',
      component: () => import('@/views/system/corEnterpriseManagement'),
      meta: {title: '系统管理', icon: 'dashboard'}
    }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/system',
    meta: {
      title: '系统管理',
    },
    children: [
      {
        path: 'corEnterpriseManagement',
        name: 'corEnterpriseManagement',
        component: () => import('@/views/system/corEnterpriseManagement'),
        meta: {
          title: '行业配置',
        }
      },
      {
        path: 'commonUserManagement',
        name: 'commonUserManagement',
        component: () => import('@/views/system/commonUserManagement'),
        meta: {
          title: '信贷产品配置',
        }
      },
      {
        path: 'routeManage',
        name: 'routeManage',
        component: () => import('@/views/system/routeManage'),
        meta: {
          title: '路由配置',
        }
      },
      {
        path: 'roleManage',
        name: 'roleManage',
        component: () => import('@/views/system/roleManage'),
        meta: {
          title: '角色配置',
        }
      },

    ]
  },



  // //信贷管理
  // {
  //   path: '/credit',
  //   component: Layout,
  //   redirect: '/creditLine/creditLine',
  //   name: 'creditLine',
  //   meta: {
  //     title: '信贷管理',
  //     icon: 'el-icon-s-help'
  //   },
  //   children: [{
  //       path: 'mailingLists',
  //       name: 'mailingLists',
  //       component: () => import('@/views/credit/creditLine'),
  //       meta: {
  //         title: '授信额度管理',
  //         icon: 'table',
  //         roles: ['admin', 'editor'],
  //         noCache: true
  //       }
  //     },
  //     {
  //       path: 'creditStandingBook',
  //       name: 'creditStandingBook',
  //       component: () => import('@/views/credit/creditStandingBook'),
  //       meta: {
  //         title: '授信台账管理',
  //         icon: 'table',
  //         roles: ['admin', 'editor'],
  //         noCache: true
  //       }
  //     },
  //     {
  //       path: 'creditPush',
  //       name: 'creditPush',
  //       component: () => import('@/views/credit/creditPush'),
  //       meta: {
  //         title: '授信推送',
  //         icon: 'table',
  //         roles: ['admin', 'editor'],
  //         noCache: true
  //       }
  //     },
  //   ]
  // },
  //用户管理
  {
    path: '/userManagement',
    component: Layout,
    redirect: '/userManagement/coreEnterprise',
    name: 'coreEnterprise',
    meta: {
      title: '用户管理',
      icon: 'el-icon-s-help'
    },
    children: [{
      path: 'coreEnterprise',
      name: 'coreEnterprise',
      component: () => import('@/views/userManagement/coreEnterprise'),
      meta: {
        title: '核心企业管理',
        icon: 'table',
        roles: ['admin', 'editor'],
        noCache: true
      }
    }, {
      path: 'domesticConsumer',
      name: 'domesticConsumer',
      component: () => import('@/views/userManagement/domesticConsumer'),
      meta: {
        title: '普通用户管理',
        icon: 'table',
        roles: ['admin', 'editor'],
        noCache: true
      }
    }, 
    

  ]
  },
  {
    path: '/userCenter',
    component: Layout,
    hidden: true,
    redirect: '/user/userCenter',
    name: 'userCenter',
    meta: {
      title: '个人中心',
      icon: 'el-icon-s-help'
    },
  },

  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

router.beforeEach((to, from, next) => {
  next();
  // if (localStorage.getItem('token')) {
  //   next();
  // } else {
  //   //如果是登录页面路径，就直接next()
  //   if (to.path === '/login') {
  //     next();
  //   } else {
  //     next('/login');
  //   }
  // }
})
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
